package com.example.xmh.utils;

import java.util.Random;

/**
 * 预约码生成工具类
 */
public class MateUtils {
    /** 预约码码表 */
    private static final char[] CODE_TABLE= {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R',
            'S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'};

    /** 随机码默认位数-- 6位 */
    private static final int DEFAULT_DIGIT = 6;

    /** 默认随机码个数-- 2个 */
    private static final int DEFAULT_NUMBER = 2;

    private MateUtils() { }

    /**  默认生成单个6位预约码 */
    public static String generateReserve() {
        StringBuilder strBuild = new StringBuilder();
        for (int i = 0; i <= DEFAULT_DIGIT; i++) {
            strBuild.append(CODE_TABLE[new Random().nextInt(36)]);
        }
        return strBuild.toString();
    }

    /**
     * 指定位数生成随机码，位数需大于0，否则返回默认6位随机码
     * @param digit 随机码的位数
     */
    public static String generateReserveWithAnyBit(int digit) {
        if (digit > 0) {
            StringBuilder strBuild = new StringBuilder();
            for (int i = 0; i <= digit; i++) {
                strBuild.append(CODE_TABLE[new Random().nextInt(36)]);
            }
            return strBuild.toString();
        }
        return generateReserve();
    }
}